package com.zsix.system.strategy.jump;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 跳转
 */
@Component
public class JumpContext {
    /**
     * 跳转策略对象
     */
    private final List<JumpStrategy> jumpStrategies;
    /**
     * 构造函数
     * @param jumpStrategies
     */
    public JumpContext(List<JumpStrategy> jumpStrategies){
        this.jumpStrategies=jumpStrategies;
    }

    /**
     * server容器
     */
    private Map<String, JumpStrategy> jumpStrategyMap=new HashMap<>();

    /**
     * 初始化
     */
    @PostConstruct
    public void init(){
        jumpStrategyMap=jumpStrategies.stream()
                .collect(Collectors.toMap(JumpStrategy::getType, o->o));
    }

    /**
     * 获取服务对象
     * @param serviceType
     * @return
     */
    public JumpStrategy getService(String serviceType){
        return jumpStrategyMap.get(serviceType);
    }
}
